#include <iostream>
#include <algorithm>
#include <set>
#include <queue>


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <cstring>

using namespace std;

#define mk make_pair
#define pb push_back
#define SZ( X ) (int)(X).size()
#define f first
#define s second

const int inf = (int)1e7;
const int mxx = (int)1e5;
int n,e;
int S;
vector< int > shop; // 0 is the initial shop
vector< vector< pair<int,int> > >E;


inline void Read(){
	scanf("%d %d",&n,&e);
	E.assign( n, vector<pair<int,int> >() );
	
	int u,v,d;
	for(int i=0;i<e;++i){
		scanf("%d %d %d",&u,&v,&d);
		assert( u>=0 && u<n );
		assert( v>=0 && v<n );		
		E[u].pb( mk(v,d) );
		E[v].pb( mk(u,d) );		
	}
	
		scanf("%d",&S);
		S+=1;
		assert( S>=0 && S<=11 );
		shop.assign(S,0);
		shop[0]=0;
		for(int i=1;i<S;++i){
			scanf("%d",&shop[i] );
			assert( shop[i]>=0 && shop[i]<n );
		}
	
}
int D[ (int)mxx+20 ];
int F[ (int)mxx+20 ];

inline void dj(int father){
	memset(F,-1,sizeof(F));
	for(int i=0;i<=mxx;++i){
		D[i]=inf;
	}
	
	set< pair<int,int>, less< pair<int,int> > > pq;
	pq.insert( mk(0,father) );
	D[ father ] =0;

		while( pq.empty()==false ){
			father = pq.begin()->s;
			pq.erase( pq.begin() );

			assert( father>=0 && father < n );
			if( F[father]!=-1 )continue;
			
			vector< pair<int,int> > cango = E[ father ];			
			for(int i = 0, j=SZ(cango); i<j; ++i ){
				int child = cango[i].f;
				int costt = cango[i].s ;
				
				assert( child>=0 && child<n)				;
				if( F[ child ]==-1 &&  ( D[father]+costt < D[child] ) ){		
					D[ child ] = D[father]+costt;
					pq.insert( mk(D[child], child) );
				}
			}
			
			F[father]=1;
		}
}
int dist[15][15];
int dp[ 15 ][ 1<<15 ];

inline int go(int cs, int mask){
	if( __builtin_popcount(mask)+1 ==S ){
		return dist[cs][0];
	}
	
	int& best = dp[ cs ][ mask ];
	if( best!=-1 )return best;
	best = (int)1e8;
	for(int i=1;i<S;++i){
		if( ( mask&(1<<i) )== 0 ){
			int d = dist[cs][i];
			int var = d+go( i , ( mask|(1<<i) ) );
			best = min( best, var );
		} 
	}
return best;
}

inline void Proc(){
	for(int i=0;i<S;++i){
		dj( shop[i] );
		for(int j=0;j<S;++j){
			dist[i][j] = D[ shop[j] ];			
		}
	}
	memset(dp,-1,sizeof(dp) );
	int var = go(0,0);
	cout<<var<<"\n";
}
int main(){
	
	
	int t;
	scanf("%d",&t);
	while(t--){
		Read();
		Proc();	
	}
	
return 0;
}
